<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;

class RoleResource extends BaseResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'code' => $this->code,
            'status' => $this->status,
            'sort' => $this->sort,
            'remark' => $this->remark,
            'menus' => $this->whenLoaded('menus', function () {
                return $this->menus->pluck('id');
            }),
            'permissions' => $this->whenLoaded('permissions', function () {
                return $this->permissions->pluck('id');
            }),
            'created_at' => $this->formatDateTime($this->created_at),
            'updated_at' => $this->formatDateTime($this->updated_at),
        ];
    }
}

